pgconn: apply a 10-second connection timeout everywhere#12
Open
brmzkw wants to merge 1 commit into
Open
Conversation
PGCONNECT_TIMEOUT=10 is injected into every subprocess environment so that pg_dump, pg_dumpall, pg_restore, and psql all time out quickly when a packet-dropping firewall is in the way. connect_timeout=10 is added to the DSN so the same limit applies to Go-side Open/Ping calls via pgx. The timeout is hardcoded (not configurable) and intentionally only covers the initial TCP handshake and authentication, not the duration of a running dump or restore. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Collaborator
Author
|
On OSX, tested with the following: Run a container: docker run --rm -ti --name test -p 9999:5432 -e POSTGRES_PASSWORD=postgres postgres:17Drop connection: echo "block drop out proto tcp to any port 9999" | sudo pfctl -ef -Run a backup: plakar -stdio at ./toto backup postgres://postgres:postgres@localhost:9999
/Users/niluje/dev/plakar/plakar/plakar: failed to backup source: rpc error: code = Unknown desc = querying server version: failed to connect to `user=postgres database=postgres`:??[::1]:9999 (localhost): tls error: write tcp [::1]:50815->[::1]:9999: write: socket is not connected??127.0.0.1:9999 (localhost): dial error: timeout: dial tcp 127.0.0.1:9999: connect: operation timed out??[::1]:9999 (localhost): failed to write startup message: write failed: write tcp [::1]:50818->[::1]:9999: write: socket is not connected??127.0.0.1:9999 (localhost): dial error: timeout: dial tcp 127.0.0.1:9999: connect: operation timed outRevert firewall: sudo pfctl -F rules
sudo pfctl -f /etc/pf.conf |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PGCONNECT_TIMEOUT=10 is injected into every subprocess environment so that pg_dump, pg_dumpall, pg_restore, and psql all time out quickly when a packet-dropping firewall is in the way. connect_timeout=10 is added to the DSN so the same limit applies to Go-side Open/Ping calls via pgx.
The timeout is hardcoded (not configurable) and intentionally only covers the initial TCP handshake and authentication, not the duration of a running dump or restore.